package com.sgb.kjwl.view.ui.activity.toBeReviewed;

import com.sgb.kjwl.api.APIManager;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.repository.DeviceRepertory;
import com.sgb.kjwl.view.ui.activity.member.AddMemberEntity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.di.Fragment;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.base.model.preference.BasePreferenceSource;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ToBeReviewModel extends BaseViewModel {
    private ReviewListActivity reviewListActivity;
    private final ToBeReviewRepertory reviewRepertory;

    public AddMemberEntity addMemberEntity = new AddMemberEntity();

    public ToBeReviewModel(ReviewListActivity reviewListActivity,ToBeReviewRepertory toBeReviewRepertory) {
        this.reviewListActivity = reviewListActivity;
        this.reviewRepertory = toBeReviewRepertory;
    }

/*if (response.body().getState() != null && response.body().getState().equals(APIManager.RESPONSE_OK)) {
        activity.setSecondFilter(response.body().getData());
    }*/
    public void getMemberApplyList(String companyNo){
            DialogHelper.showProgressDialog(reviewListActivity, null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getToReviewAPI().getList(companyNo).enqueue(new Callback<BaseEntity<List<MemberApplyEntry>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<MemberApplyEntry>>> call, Response<BaseEntity<List<MemberApplyEntry>>> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body().getState() != null && response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    reviewListActivity.setDataList(response.body().getData());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<MemberApplyEntry>>> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }


    public void addMember(){
        DialogHelper.showProgressDialog(reviewListActivity, null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getToReviewAPI().addMember(addMemberEntity).enqueue(new Callback<BaseEntity>() {
            @Override
            public void onResponse(Call<BaseEntity> call, Response<BaseEntity> response) {
                DialogHelper.dismissProgressDialog();
                if (response.body().getState() != null && response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    reviewListActivity.addSuccess();
                }
            }

            @Override
            public void onFailure(Call<BaseEntity> call, Throwable t) {
                DialogHelper.dismissProgressDialog();
            }
        });
    }



}
